fix(kimi): gate --work-dir flag on probe, like --print (#1476)#1483
Open
chenhg5 wants to merge 1 commit into
Open
fix(kimi): gate --work-dir flag on probe, like --print (#1476)#1483chenhg5 wants to merge 1 commit into
chenhg5 wants to merge 1 commit into
Conversation
Same pattern as the #1456 / PR #1461 --print fix. Newer Kimi Code CLI builds no longer accept --work-dir, exiting with `error: unknown option --work-dir` whenever the user's config sets a non-default workspace directory. - agent/kimi/probe.go: kimiFlagSupport gains a WorkDir bool; the probe fills it from `kimi --help` (parseKimiHelpFlags already scans the --work-dir token, no parser changes needed). - agent/kimi/session.go buildArgs: --work-dir is now emitted only when flagSupport.WorkDir is true. The agent still runs in the correct directory via exec.Command.Dir (set separately), so omitting the flag on modern CLIs is functionally equivalent for users on default dirs and graceful for users on non-default dirs whose CLI just ignores it. - agent/kimi/probe_test.go: extend the legacy test to assert --work-dir is detected, add modernKimiHelpWithoutWorkDir constant that mirrors the build the reporter hits, plus full TestKimiFlagSupport_LegacyHelpSetsWorkDir / TestKimiFlagSupport_ModernWithoutWorkDir coverage of the probe mapping. - agent/kimi/session_test.go: TestBuildArgs_WorkDirFlagGated (no flag on modern CLI) + TestBuildArgs_WorkDirFlagEmitted (legacy CLI keeps it). Also asserts the work-dir value doesn't leak into args when the gate is closed, catching a partial-gate future bug. go test ./agent/kimi/... — all pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1476
问题
Kimi Code CLI builds newer than what #1456 covered dropped the
--work-dirflag. Passing it now produces:
The reporter (
#1476,v1.4.1, Kimi Code agent) hits this on every spawnbecause
session.go:97-99always appended the flag whenever a non-defaultworkDirwas set. The #1461 / #1456 fix gated--printthe same way; thisPR closes the gap for
--work-dir.改动
Follows the exact same probe-based pattern as #1456 / PR #1461 (referenced
for both users and reviewers who already validated that approach).
agent/kimi/probe.gokimiFlagSupportgainsWorkDir bool.probeKimiFlagspopulates it from the existingparseKimiHelpFlagsmap:agent/kimi/session.goexec.Command.Diris set on the spawned
*exec.Cmd(downstream of this line) — same as inthe fix(kimi): conditionally pass --print so newer Kimi Code CLI works (#1456) #1461 fix.
agent/kimi/probe_test.goTestParseKimiHelpFlags_LegacyAdvertisesPrintnow also assertsflags["--work-dir"]istrue(legacy CLI supports it).modernKimiHelpWithoutWorkDirmirrors the Kimi Code CLIbuild the reporter hits (no
--print, no--work-dir).TestParseKimiHelpFlags_ModernWithoutWorkDirasserts neither flagis detected on the deeper-no-work-dir surface.
TestParseKimiHelpFlags_ModernHidesPrintleft intact (itcovers the in-between surface where
--printis gone but--work-dirstill exists — useful regression coverage).
TestKimiFlagSupport_LegacyHelpSetsWorkDir+TestKimiFlagSupport_ModernWithoutWorkDirexercise the full probe-mapping, not just
parseKimiHelpFlags, since that's whatbuildArgsactually consumes.agent/kimi/session_test.goTestBuildArgs_WorkDirFlagGated—workDir=/,flagSupport{WorkDir:false}→
--work-dirMUST NOT appear, AND the value/MUST NOT leak into args(catches a partial-gate bug where only the flag name is dropped).
TestBuildArgs_WorkDirFlagEmitted—workDir=/,flagSupport{WorkDir:true}→
--work-dir /MUST appear (legacy CLI keeps non-default dir support).触发条件 / trade-off
parseKimiHelpFlagsinstead of adding a new parser?--work-diralready appears in the help-text of both legacy and thein-between build the existing
modernKimiHelpconstant models. Theexisting parser picks it up the same way it picked up
--print— nonew parser logic, no new layout assumptions.
modernKimiHelpWithoutWorkDirinstead of editingmodernKimiHelp? ThemodernKimiHelpconstant is anchored in the[Bug] ❌ 错误: error: unknown option '--print' (Did you mean --prompt?) #1456 fix history; editing it would silently invalidate that test's
assertion contract. Two-realistic-surfaces is the cleaner modeling.
cmd.Diris setunconditionally, so whether the CLI sees
--work-dir $Xor just takescwd from
cmd.Dir, the agent runs in the same directory. The onlypractical difference is users on non-default dirs whose modern CLI
previously crashed: they now get clean startup (cwd fallback).
--work-dirin help, the probe sees it,buildArgsstill emits it.验证
gofmt -l agent/kimi/— cleango vet ./agent/kimi/...— cleango test -count=1 ./agent/kimi/...— all pass (4 prior + 6 new =10 tests in the probe/session suites)
不做什么
etc. each have their own flag handling; out of scope)
kimi --help解析 + 短超时fallback to modern surface on probe failure)
buildArgs/kimiFlagSupport— 仅加一个 bool 字段关联
group_reply_allfor QQ platform) 是独立PR,本次不合并。
🤖 Generated with Claude Code